## --------------------------------------------------------------------------

import os

from datetime import datetime

import numpy

## --------------------------------------------------------------------------

def DateHour(filename):
    # get year, month, day, hour from filename

    where = filename.find('/')
    # works for zero and one slash, but not for more!

    yy = int(filename[where+1:where+3])
    mm = int(filename[where+3:where+5])
    dd = int(filename[where+5:where+7])
    hh = int(filename[where+7:where+9])

    if yy < 50:
        year = yy+2000
    else:
        year = yy+1900

    day = datetime(year, mm, dd)
    doy = (day - datetime(year, 1, 1)).days + 1

    return (year, mm, dd, hh, doy)

## --------------------------------------------------------------------------

def Date2filename(year=2011, month=1, day=1, hour=0, base="/data/missions/neutronmonitor/NM64/2011/bin"):
    # get filename from year, month, day, hour

    yy = year % 100
    filename="%s/%02i%02i%02i%02i.bin" %(base, yy, month, day, hour)
    return filename
    
## --------------------------------------------------------------------------

if __name__=="__main__":
    print "DateHour."
